public class Test {
    public static void main(String[] args) {
        int[] nums = {1,3,5,6};
        int ret = searchInsert(nums,0);
        System.out.println(ret);
    }

    //搜索插入位置
    public static int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int mid = (left + right) / 2;
        while(left <= right){
            if(nums[mid] == target){
                return mid;
            }else if(nums[mid] > target){
                right = mid - 1;;
                mid = (left + right) / 2;
            }else {
                left = mid + 1;
                mid = (left + right) / 2;
            }
        }
        if(right < 0){
            return 0;
        }else {
            return mid + 1;
        }
    }
}
